package com.blyat.xsoft.kernel.component.mybatis.dialect;

/**
 * @author syh
 * @date 2019/8/26
 **/
public class MySQLDialect extends AbstractDialect {
    public MySQLDialect() {
    }

    public String getLimitString(String sql, int offset, int limit) {
        return this.getLimitString(sql, offset, Integer.toString(offset), Integer.toString(limit));
    }

    public boolean supportsLimit() {
        return true;
    }

    public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) {
        StringBuilder stringBuilder = new StringBuilder(sql);
        stringBuilder.append(" limit ");
        if (offset > 0) {
            stringBuilder.append(offsetPlaceholder).append(",").append(limitPlaceholder);
        } else {
            stringBuilder.append(limitPlaceholder);
        }

        return stringBuilder.toString();
    }

    @Override
    protected String getSqlPattern() {
        return "\\blike\\b\\s*concat\\s*\\(\\s*(['\"]%['\"],)?\\s*#\\{\\s*(\\w+)(\\.\\w+)?\\s*\\}\\s*(,\\s*['\"]%['\"])?\\s*\\)";
    }
}
